package com.starhub.engine.directory.controller;

import com.starhub.common.bean.ResultResp;
import com.starhub.common.security.util.SecurityUtils;
import com.starhub.common.sys.user.LoginUser;
import com.starhub.engine.directory.request.DirectoryShareBsRequest;
import com.starhub.engine.directory.service.DirectoryInfoService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.starhub.engine.directory.result.DirectoryShareDealListResult;
import com.starhub.engine.directory.result.DirectoryShareDealResult;

@Api(value="目录权限管理", tags = {"附件目录权限管理"},description = "编写者:孙赛赛-sss" )
@RestController
@RequestMapping("/engine/starhub/directoryShare")
public class DirectoryShareConfigController {
    @Autowired
    private DirectoryInfoService directoryInfoService;

    private static final Logger log = LoggerFactory.getLogger(DirectoryShareConfigController.class);

    @ApiOperation(value = "根据目录ID获取共享信息", notes = "根据目录ID获取共享信息")
    @PostMapping("/getDirectoryShareList")
    public ResultResp<DirectoryShareDealListResult> getDirectoryShareList(@RequestBody DirectoryShareBsRequest directoryShareBsRequest){
        try {
            return ResultResp.success( directoryInfoService.getDirectoryShareList(directoryShareBsRequest.getDirectoryId()));
        }catch (Exception e){
            return ResultResp.fail(e.getMessage(), e);
        }
    }
    @ApiOperation(value = "新增目录权限", notes = "新增目录权限")
    @PostMapping("/grantDirectoryUserShare")
    public ResultResp<DirectoryShareDealResult> grantDirectoryUserShare(@RequestBody DirectoryShareBsRequest directoryShareBsRequest){
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            return ResultResp.success(directoryInfoService.grantDirectoryUserShare(directoryShareBsRequest,user));
        }catch (Exception e){
            return ResultResp.fail(e.getMessage(), e);
        }
    }

    @ApiOperation(value = "删除目录权限", notes = "删除目录权限")
    @PostMapping("/delDirectoryUserShare")
    public ResultResp<DirectoryShareDealResult> delDirectoryUserShare(@RequestBody DirectoryShareBsRequest directoryShareBsRequest){
        try {
            LoginUser user = SecurityUtils.getCurrentUser();
            return ResultResp.success(directoryInfoService.delDirectoryUserShare(directoryShareBsRequest,user));
        }catch (Exception e){
            return ResultResp.fail(e.getMessage(), e);
        }
    }
}
